using System;
using UnityEngine;
using UnityEngine.Networking;

namespace Voodoo.Sauce.Common.Font.Network
{
	public abstract class AbstractWebRequestHandler : IWebRequestHandler
	{
		protected Action<UnityWebRequest> _onSuccess;

		protected Action<UnityWebRequest> _onError;

		protected AbstractWebRequestHandler(Action<UnityWebRequest> onSuccess, Action<UnityWebRequest> onError)
		{
			_onSuccess = onSuccess;
			_onError = onError;
		}

		public virtual void OnSuccess(UnityWebRequest webRequest)
		{
			_onSuccess?.Invoke(webRequest);
		}

		public virtual void OnError(UnityWebRequest webRequest)
		{
			Debug.LogError("unity web request with url : " + webRequest.url + " " + webRequest.responseCode + "\nFailed with message : \n" + webRequest.error);
			_onError?.Invoke(webRequest);
		}
	}
}
